//
//  UIScrollView+MJRefreshAdd.m
//  MyMainDemo
//
//  Created by FM123 on 2018/3/6.
//  Copyright © 2018年 LiMin. All rights reserved.
//

#import "UIScrollView+MJRefreshAdd.h"
#import "FMHeadRefreshView.h"
#import "FMFooterRefreshView.h"
@implementation UIScrollView (MJRefreshAdd)
-(void)setHeader:(FMHeadRefreshView *)header{
    
    //通过键值"header"将自己的header对象绑定起来
    objc_setAssociatedObject(self,"header", header,OBJC_ASSOCIATION_ASSIGN);
}
-(void)setFooter:(FMFooterRefreshView *)footer{
    
    objc_setAssociatedObject(self,"footer", footer,OBJC_ASSOCIATION_ASSIGN);
    
}
-(FMHeadRefreshView*)header{
 //通过键值"header"读取之前绑定的对象
    return objc_getAssociatedObject(self,"header");
    
}
-(FMFooterRefreshView*)footer{
    
    return objc_getAssociatedObject(self,"footer");
    
}
-(void)addRefreshWithTarget:(id)target  headerSelect:(SEL)headerSelect  footerSelect:(SEL)footerSelect
{
    if (headerSelect){
        //添加头部刷新
        FMHeadRefreshView *header = [[FMHeadRefreshView alloc]initWithFrame:CGRectMake(0, -60,self.bounds.size.width,60)];
        header.refreshSelecter = headerSelect;
        header.selecterTarget = target;
        header.superScrollView =self;
        [self addSubview:header];
         self.header = header;
    }
    if (footerSelect){
        //添加尾部刷新
        FMFooterRefreshView *footer = [[FMFooterRefreshView alloc]initWithFrame:CGRectMake(0,self.contentSize.height,self.bounds.size.width,K_FOOTER_REFRESHVIEW_WH)];
        footer.refreshSelecter = footerSelect;
        footer.selecterTarget = target;
        footer.superScrollView =self;
//        footer.scale =1.0;
        [self addSubview:footer];
         self.footer = footer;
    }
}
//停止头部刷新

-(void)stopHeaderRefresh {
    
    [self.header stopRefresh];
    
}

//停止尾部刷新

-(void)stopFooterRefresh {
    
    [self.footer stopRefresh];
    
}



//开始头部刷新

-(void)startHeaderRefresh {
    
    [self.header startRefresh];
    
}
//开始尾部刷新

-(void)startFooterRefresh{
    
    [self.footer startRefresh];
    
}
@end
